package com.zlm.IO.ByteStream;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @author 13026
 */
public class FileCopy {
    public static void main(String[] args) throws IOException {
        // 逐个字节拷贝
        FileInputStream fos = new FileInputStream("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\ByteStream\\FilesPackage\\a.txt");
        FileOutputStream fos2 = new FileOutputStream("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\ByteStream\\FilesPackage\\a_copy.txt");

        int b;
        while ((b = fos.read())!=-1){
            fos2.write(b);
        }

        // 记得关流
        fos.close();
        fos2.close();

        // 字节数组拷贝
        FileInputStream fos3 = new FileInputStream("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\ByteStream\\FilesPackage\\a.txt");
        FileOutputStream fos4 = new FileOutputStream("D:\\myProject\\javaTest\\oneModule\\src\\com\\zlm\\IO\\ByteStream\\FilesPackage\\a_copy_2.txt");

        byte[] bytes = new byte[1024];
        int length;
        while ((length = fos3.read(bytes))!=-1){
            fos4.write(bytes,0,length);
            System.out.println(new String(bytes));
        }

        // 记得关流
        fos3.close();
        fos4.close();
    }
}
